import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["userId", "userOrganizationId"],
    _excluded2 = ["userId", "userOrganizationId"],
    _excluded3 = ["userId"],
    _excluded4 = ["userId"],
    _excluded5 = ["userId"];

/**
 * subAccountService - 子账户平台级服务
 * @date 2018-12-15

 */
import { parseParameters } from 'utils/utils';
import { CPAAS_IAM } from 'utils/config';
import request from 'utils/request';
/**
 * 查询子账户的信息-分页
 * @param {object} params
 * @return {Promise}
 */

export function subAccountQueryPage(_x) {
  return _subAccountQueryPage.apply(this, arguments);
}
/**
 * 更新子账户的密码
 * @param {number} userId 用户id
 * @param {number} organizationId 用户所属租户id
 * @param {string} params.password 密码
 * @return {Promise}
 */

function _subAccountQueryPage() {
  _subAccountQueryPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var parseParams;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            parseParams = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/paging"), {
              query: parseParams,
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _subAccountQueryPage.apply(this, arguments);
}

export function subAccountPasswordUpdate(_x2) {
  return _subAccountPasswordUpdate.apply(this, arguments);
}
/**
 * 更新子账户的密码
 * @param {number} userId 用户id
 * @param {number} organizationId 用户所属租户id
 * @param {string} params.password 密码
 * @param {string} params.originalPassword 修改自己需要原密码
 * @return {Promise}
 */

function _subAccountPasswordUpdate() {
  _subAccountPasswordUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref) {
    var userId, userOrganizationId, params;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            userId = _ref.userId, userOrganizationId = _ref.userOrganizationId, params = _objectWithoutProperties(_ref, _excluded);
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/").concat(userId, "/admin-password"), {
              method: 'PUT',
              body: _objectSpread(_objectSpread({}, params), {}, {
                organizationId: userOrganizationId
              })
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _subAccountPasswordUpdate.apply(this, arguments);
}

export function subAccountPasswordUpdateSelf(_x3) {
  return _subAccountPasswordUpdateSelf.apply(this, arguments);
}
/**
 * 查询 可分配角色
 * @param {number} params.tenantId - 用户所属租户id
 * @param {number} params.name - 角色名
 * @param {number} params.excludeRoleIds - 新分配 角色id
 * @param {number} params.excludeUserIds - 已分配 角色id
 * @return {Promise<void>}
 */

function _subAccountPasswordUpdateSelf() {
  _subAccountPasswordUpdateSelf = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref2) {
    var userId, userOrganizationId, params;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            userId = _ref2.userId, userOrganizationId = _ref2.userOrganizationId, params = _objectWithoutProperties(_ref2, _excluded2);
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/password"), {
              method: 'PUT',
              body: params
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _subAccountPasswordUpdateSelf.apply(this, arguments);
}

export function subAccountUserRolesQuery(_x4) {
  return _subAccountUserRolesQuery.apply(this, arguments);
}
/**
 * 查询 已分配角色
 * @return {Promise<void>}
 */

function _subAccountUserRolesQuery() {
  _subAccountUserRolesQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/roles/self/user-assignable-roles"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _subAccountUserRolesQuery.apply(this, arguments);
}

export function subAccountCurrentUserRoles(_x5) {
  return _subAccountCurrentUserRoles.apply(this, arguments);
}
/**
 * 查询 子账号详情
 */

function _subAccountCurrentUserRoles() {
  _subAccountCurrentUserRoles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref3) {
    var userId, params, parsedParams;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            userId = _ref3.userId, params = _objectWithoutProperties(_ref3, _excluded3);
            parsedParams = parseParameters(params);
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/member-roles/user-roles/").concat(userId), {
              method: 'GET',
              query: parsedParams
            }));

          case 3:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _subAccountCurrentUserRoles.apply(this, arguments);
}

export function subAccountQuery(_x6, _x7) {
  return _subAccountQuery.apply(this, arguments);
}
/**
 * 新建子账号
 * @return {Promise<void>}
 */

function _subAccountQuery() {
  _subAccountQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(userId, params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/").concat(userId, "/info"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _subAccountQuery.apply(this, arguments);
}

export function subAccountCreate(_x8) {
  return _subAccountCreate.apply(this, arguments);
}
/**
 * 更新子账号
 * @return {Promise<void>}
 */

function _subAccountCreate() {
  _subAccountCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _subAccountCreate.apply(this, arguments);
}

export function subAccountUpdate(_x9) {
  return _subAccountUpdate.apply(this, arguments);
}
/**
 * 解锁账号
 * @param {number} userId - 用户id
 */

function _subAccountUpdate() {
  _subAccountUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _subAccountUpdate.apply(this, arguments);
}

export function subAccountUserUnlock(_x10) {
  return _subAccountUserUnlock.apply(this, arguments);
}
/**
 * 删除角色
 * @param {object[]} memberRoleList - 删除的角色
 */

function _subAccountUserUnlock() {
  _subAccountUserUnlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(userId) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/").concat(userId, "/unlocked"), {
              method: 'POST'
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _subAccountUserUnlock.apply(this, arguments);
}

export function subAccountUserRolesRemove(_x11) {
  return _subAccountUserRolesRemove.apply(this, arguments);
}
/**
 * 查询 可分配的用户组
 * @param {number} params.tenantId - 用户所属租户id
 * @param {number} params.name - 角色名
 * @param {number} params.excludeRoleIds - 新分配 角色id
 * @param {number} params.excludeUserIds - 已分配 角色id
 * @return {Promise<void>}
 */

function _subAccountUserRolesRemove() {
  _subAccountUserRolesRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(memberRoleList) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/member-roles/batch-delete"), {
              method: 'DELETE',
              body: memberRoleList
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _subAccountUserRolesRemove.apply(this, arguments);
}

export function subAccountUserGroupsQuery(_x12) {
  return _subAccountUserGroupsQuery.apply(this, arguments);
}
/**
 * 查询 已分配的用户组
 * @return {Promise<void>}
 */

function _subAccountUserGroupsQuery() {
  _subAccountUserGroupsQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    var parsedParams;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            parsedParams = parseParameters(params);
            return _context11.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(parsedParams.userId, "/user-group-assigns/exclude-groups"), {
              method: 'GET',
              query: parsedParams
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _subAccountUserGroupsQuery.apply(this, arguments);
}

export function subAccountCurrentGroupRoles(_x13) {
  return _subAccountCurrentGroupRoles.apply(this, arguments);
}
/**
 * 添加用户组
 * @return {Promise<void>}
 */

function _subAccountCurrentGroupRoles() {
  _subAccountCurrentGroupRoles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref4) {
    var userId, params, parsedParams;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            userId = _ref4.userId, params = _objectWithoutProperties(_ref4, _excluded4);
            parsedParams = parseParameters(params);
            return _context12.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(userId, "/user-group-assigns"), {
              method: 'GET',
              query: parsedParams
            }));

          case 3:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _subAccountCurrentGroupRoles.apply(this, arguments);
}

export function addUserGroup(_x14) {
  return _addUserGroup.apply(this, arguments);
}
/**
 * 删除用户组
 * @param {object[]} memberRoleList - 删除的角色
 */

function _addUserGroup() {
  _addUserGroup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    var userId, memberGroupList;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            userId = params.userId, memberGroupList = params.memberGroupList;
            return _context13.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(userId, "/user-group-assigns"), {
              method: 'POST',
              body: memberGroupList
            }));

          case 2:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _addUserGroup.apply(this, arguments);
}

export function deleteUserGroup(_x15) {
  return _deleteUserGroup.apply(this, arguments);
}

function _deleteUserGroup() {
  _deleteUserGroup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    var userId, remoteRemoveDataSource;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            userId = params.userId, remoteRemoveDataSource = params.remoteRemoveDataSource;
            return _context14.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(userId, "/user-group-assigns"), {
              method: 'DELETE',
              body: remoteRemoveDataSource
            }));

          case 2:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _deleteUserGroup.apply(this, arguments);
}

export function queryDimension() {
  return _queryDimension.apply(this, arguments);
}

function _queryDimension() {
  _queryDimension = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            return _context15.abrupt("return", request("".concat(CPAAS_IAM, "/v1/doc-type/dimensions/biz"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _queryDimension.apply(this, arguments);
}

export function queryEmployee(_x16) {
  return _queryEmployee.apply(this, arguments);
}

function _queryEmployee() {
  _queryEmployee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    var parsedParams, userId, res;
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            parsedParams = parseParameters(params);
            userId = parsedParams.userId, res = _objectWithoutProperties(parsedParams, _excluded5);
            return _context16.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/users/").concat(userId, "/user-employee-assigns"), {
              query: res,
              method: 'GET'
            }));

          case 3:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _queryEmployee.apply(this, arguments);
}